#include "head.h"

//通过用户名查找用户id
int get_user_id(const char *user_name, MYSQL *mysql){
    char query[1024] = {0};
    sprintf(query, "select * from users where username = '%s'", user_name);

    //查找用户信息
    if(mysql_query(mysql, query)){
        // printf("%s\n", mysql_error(mysql));
        LOG(ERROR, user_name, "get_user_id select", mysql_error(mysql));
        return -1;
    }

    MYSQL_RES *res = mysql_store_result(mysql);
    if(res == NULL){
        return -1;
    }

    MYSQL_ROW row = mysql_fetch_row(res);

    int user_id = atoi(row[0]);

    mysql_free_result(res);
    return user_id;
}
